package com.moshme.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moshme.project.domain.ProjectStep;
import com.moshme.project.mapper.ProjectStepMapper;
import com.moshme.project.mapper.ProjectStepUserMapper;
import com.moshme.project.service.ProjectStepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 望夜
 * @date 2023/8/22---16:50
 * @SuppressWarnings({"all"})
 */
@Service
public class ProjectStepServiceImpl extends ServiceImpl<ProjectStepMapper, ProjectStep> implements ProjectStepService {

    @Autowired(required = false)
    private ProjectStepUserMapper dockStepUserMapper;

    /**
     * 根据项目id先删除阶段人员关联，再删阶段
     * @param projectId
     */
    @Override
    public void deleteStepsByProjectId(Long projectId) {
        LambdaQueryWrapper<ProjectStep> wrapper = new LambdaQueryWrapper<ProjectStep>().eq(ProjectStep::getProjectId, projectId);
        List<ProjectStep> dockSteps = baseMapper.selectList(wrapper);
        for (ProjectStep dockStep : dockSteps) {
            dockStepUserMapper.deleteById(dockStep.getStepId());
        }
        baseMapper.delete(wrapper);
    }
}
